# -  *  - coding:utf-8  -  *  -
import sys
import time

from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By
from public.common.basepage import Page


class ProductionUserPage(Page):
    url = "http://120.24.81.195/qrweb/admin/producer/index.html"

    def __init__(self, url=url):
        super().__init__(url)
        self.add_user = (By.CLASS_NAME, "upload_btn")
        self.is_state = (By.ID, "state")
        self.search = (By.NAME, "bz")
        self.sort = (By.CLASS_NAME, "margin_top5")

    def is_account_up_sort(self):
        # 账号排序
        # 是否连接数据库进行数据校验
        scrip = "document.getElementsByClassName('arrow arrow_up')[0].click();"
        self.script(scrip)

    def state(self):
        status = list()
        click_status = list()
        for i in range(10):
            els = self.get_elments(*self.is_state)
            status.append(els[i].text)
            els[i].click()
            self.dirver.switch_to.alert.accept()
            time.sleep(0.5)
            els = self.get_elments(*self.is_state)
            click_status.append(els[i].text)
        return status, click_status

    def search(self,search):
        self.get_element(*self.search).send_keys(search)
        self.get_element(*self.sort)


    def test_state(self):
        # 启用/禁用
        statu, click_statu = self.state()
        for i in range(len(statu)):
            if statu[i] == click_statu[i]:
                print("{0}-->{1}".format(statu[i], click_statu[i]))
            if statu[i] not in (("禁用", "启用")):
                print(statu[i])
            if click_statu[i] not in (("禁用", "启用")):
                print(click_statu[i])


if __name__ == "__main__":
    p = ProductionUserPage()
    p.test_state()
    p.dirver.quit()
